package org.proddevplm.business.activity;

import java.util.Map;

import org.proddevplm.business.activity.constants.ActivityConstants;
import org.proddevplm.business.api.AController;
import org.proddevplm.constants.ControllerConstants;
import org.proddevplm.dao.data.activities.Activity;

public class ActivityController extends AController{

	@Override
	public Object execute(int command, Object data) {
		Map<String, Object> activityMap = (Map<String, Object>)data;
		int productId = (Integer)getSession().getAttribute("productId");
		Activity currentActivity;
		
		switch(command){
		
		case ActivityConstants.UPDATE_ACTIVITY:
			String name = (String) activityMap.get("activityName");
			currentActivity = getDaoManager().getActivityManager().getActivityByNameandProductId(name, productId);
			if (currentActivity!=null){
				currentActivity.setActivityLifeCycle("Approved");
				getDaoManager().getActivityManager().updateActivity(currentActivity);
			}
			
			putOnState(ControllerConstants.NEXT_PAGE, "content/project/projectPage.jsp");
            putOnSession("currentTab", "tab4");
            break;
            
		case ActivityConstants.CHANGE_STATUS:
			currentActivity = getDaoManager().getActivityManager().getActivityByNameandProductId((String) activityMap.get("activityName"), productId);
			if(currentActivity!=null){
				currentActivity.setActivityLifeCycle("Under review");
				getDaoManager().getActivityManager().updateActivity(currentActivity);
			}
			putOnState(ControllerConstants.NEXT_PAGE, "content/project/projectPage.jsp");
            putOnSession("currentTab", "tab4");
            break;
            
		case ActivityConstants.ADD_COMMENT:
			currentActivity = getDaoManager().getActivityManager().getActivityByNameandProductId((String) activityMap.get("activityName"), productId);
			currentActivity.setComments((String)activityMap.get("comment"));
			getDaoManager().getActivityManager().updateActivity(currentActivity);
			putOnState(ControllerConstants.NEXT_PAGE, "content/project/projectPage.jsp");
            putOnSession("currentTab", "tab4");
            break;
            
		case ActivityConstants.REMOVE_ACTIVITY:
			getDaoManager().getActivityManager().removeActivity(activityMap.get("activityName").toString(), productId);
			putOnState(ControllerConstants.NEXT_PAGE, "content/project/projectPage.jsp");
            putOnSession("currentTab", "tab3");
            break;
		}
		return null;
	}

}
